/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package com.pras.skripsi.sql;

import com.mysql.jdbc.jdbc2.optional.MysqlDataSource;
import java.sql.Connection;
import java.sql.SQLException;

/**
 *
 * @author wisnu
 */
public class Database {

    private static Connection connection;
    private static DataPasienDao dataPasienDao;

    private Database() {
    }

    protected static Connection getConnection() throws SQLException {
        if (connection == null) {
            MysqlDataSource dataSource = new MysqlDataSource();
            dataSource.setURL("jdbc:mysql://127.0.0.1:3306/buta_warna");
            dataSource.setUser("root");
            dataSource.setPassword("");

            connection = dataSource.getConnection();
        }
        return connection;
    }

    public static DataPasienDao getDataPasienDao() throws SQLException {
        if (dataPasienDao == null) {
            dataPasienDao = new DataPasienDao(getConnection());
        }
        return dataPasienDao;
    }

    public static Database getInstance() {
        return DatabaseHolder.INSTANCE;
    }

    private static class DatabaseHolder {

        private static final Database INSTANCE = new Database();
    }
}
